using System.ComponentModel;

namespace DeSleeper.Library
{
    /// <summary>
    /// Represents a method that handles a cancelable event.
    /// </summary>
    /// <typeparam name="T">Event payload data type.</typeparam>
    /// <param name="sender">The source of the event.</param>
    /// <param name="args">Data for the cancelable event.</param>
    public delegate void CancelDataEventHandler<T>(object sender, CancelDataEventArgs<T> args);

    ///<summary>
    /// Provides data for a cancelable event.
    ///</summary>
    public static class CancelDataEventArgs
    {
        /// <summary>
        /// Creates a generic event.
        /// </summary>
        /// <param name="data">The events payload data.</param>
        public static CancelDataEventArgs<T> Create<T>(T data) { return new CancelDataEventArgs<T>(data); }
        /// <summary>
        /// Creates a generic event.
        /// </summary>
        /// <param name="data">The events payload data.</param>
        /// <param name="cancel">The default state, canceled or uncanceled.</param>
        public static CancelDataEventArgs<T> Create<T>(T data, bool cancel) { return new CancelDataEventArgs<T>(data, cancel); }
    }

    ///<summary>
    /// Provides data for a cancelable event.
    ///</summary>
    ///<typeparam name="T">Event payload data type.</typeparam>
    public class CancelDataEventArgs<T> : CancelEventArgs, IDataEventArgs<T>
    {
        /// <summary>
        /// The events payload data.
        /// </summary>
        public T Data { get; private set; }

        /// <summary>
        /// Creates a generic event.
        /// </summary>
        /// <param name="data">The events payload data.</param>
        public CancelDataEventArgs(T data)
        {
            Data = data;
        }

        /// <summary>
        /// Creates a generic event.
        /// </summary>
        /// <param name="data">The events payload data.</param>
        /// <param name="cancel">The default state, canceled or uncanceled.</param>
        public CancelDataEventArgs(T data, bool cancel)
            : base(cancel)
        {
            Data = data;
        }
    }
}